package com.v5ba;

import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull;

public class EnabledAction extends AnAction {
    @Override
    public void actionPerformed(@NotNull AnActionEvent e) { }

    @Override
    public void update(@NotNull AnActionEvent e) {
        super.update(e);
        final Project project = e.getProject();
        final Editor editor = e.getData(CommonDataKeys.EDITOR);
        boolean menuAllowed = false;
        if (editor != null && project != null){
            menuAllowed = true;
        }
        // 隐藏
        //e.getPresentation().setVisible(menuAllowed);
        e.getPresentation().setEnabled(menuAllowed);
    }
}
